package cn.itsource.listener;

import cn.itsource.blog.permission.PermissionScan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener//申明自定义的web监听器，被容器注册和使用
@Slf4j
public class PermissionScanListener implements ServletContextListener {

    @Autowired
    private PermissionScan xx;
    @Override
    public void contextInitialized(ServletContextEvent sce) {
       new Thread(()->{
           WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
           PermissionScan permissionScan = (PermissionScan) webApplicationContext.getBean("permissionScan");
           System.out.println(xx);
           permissionScan.scan();
       }).start();
    }
}